package view;

import model.Time;
import view.AbstractTimeView;

/**
 * TimeView.java
 * @author Diego Schmaedech
 * @version 1.0
 * @since Release Beta
 * @link  http://code.google.com/p/economylabs
 * Created on August 2, 2008, 2:34 AM
 */
public class TimeView extends AbstractTimeView {
 
    /** Creates new form TimeView
     * @param time 
     */
    public TimeView( Time time ) {
        super( time );         
        initComponents();
        updateDisplay();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jlTimer = new javax.swing.JLabel();
        jtfTimer = new javax.swing.JTextField();
        jlPeriod = new javax.swing.JLabel();
        jlInterval = new javax.swing.JLabel();
        jtfInterval = new javax.swing.JTextField();
        jtfPeriod = new javax.swing.JTextField();
        jpbTimer = new javax.swing.JProgressBar();

        setBackground(new java.awt.Color(254, 254, 254));
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(expecon.ExpEconApp.class).getContext().getResourceMap(TimeView.class);
        setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("borderTime.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("Form.border.titleFont"), new java.awt.Color(113, 196, 243))); // NOI18N
        setPreferredSize(new java.awt.Dimension(400, 100));

        jlTimer.setFont(new java.awt.Font("DejaVu Sans", 1, 13));
        jlTimer.setText(resourceMap.getString("jlTimer.text")); // NOI18N

        jtfTimer.setColumns(20);
        jtfTimer.setEditable(false);
        jtfTimer.setText(getTime().getTimestamp());

        jlPeriod.setFont(new java.awt.Font("DejaVu Sans", 1, 13));
        jlPeriod.setText(resourceMap.getString("jlPeriod.text")); // NOI18N

        jlInterval.setFont(new java.awt.Font("DejaVu Sans", 1, 13));
        jlInterval.setText(resourceMap.getString("jlInterval.text")); // NOI18N

        jtfInterval.setColumns(20);
        jtfInterval.setEditable(false);
        jtfInterval.setText(String.valueOf(getTime().getInterval()));

        jtfPeriod.setColumns(20);
        jtfPeriod.setEditable(false);
        jtfPeriod.setText(String.valueOf(getTime().getPeriod()));

        jpbTimer.setBackground(new java.awt.Color(254, 210, 156));
        jpbTimer.setMaximum(getTime().getInterval());
        jpbTimer.setValue(getTime().getTimerCounter());
        jpbTimer.setStringPainted(true);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlPeriod)
                    .addComponent(jlInterval))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jtfInterval, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jtfPeriod, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jlTimer)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jtfTimer, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jpbTimer, 0, 0, Short.MAX_VALUE))
                .addGap(25, 25, 25))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlPeriod)
                    .addComponent(jtfPeriod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlTimer)
                    .addComponent(jtfTimer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlInterval)
                    .addComponent(jtfInterval, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jpbTimer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jlInterval;
    private javax.swing.JLabel jlPeriod;
    private javax.swing.JLabel jlTimer;
    private javax.swing.JProgressBar jpbTimer;
    private javax.swing.JTextField jtfInterval;
    private javax.swing.JTextField jtfPeriod;
    private javax.swing.JTextField jtfTimer;
    // End of variables declaration//GEN-END:variables
  
    @Override
    public void updateDisplay() {
     // set text in balanceTextField to formatted balance
     jtfInterval.setText( String.valueOf( getTime().getInterval() ) );
     jtfPeriod.setText( String.valueOf( getTime().getPeriod() ) );
     jtfTimer.setText( String.valueOf( getTime().getTimestamp() ) ); 
     jpbTimer.setValue( getTime().getTimerCounter() );
  }
}
